package control
{
	import flash.events.Event;
	
	import model.ModelLocator;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.RemoteObject;
	
	import view.Markers;
	public class DeleteAMyMarker
	{
		internal var theModel:ModelLocator = ModelLocator.getInstance();
		private var DeleteAMyMarkerRO:RemoteObject;
		public var mark:view.Markers;
		public function DeleteAMyMarker(mark:view.Markers)
		{
			this.mark = mark;
			DeleteAMyMarkerRO = new RemoteObject();
			DeleteAMyMarkerRO.destination="DeleteAMyMarker";
			DeleteAMyMarkerRO.doDeleteAMyMarker.addEventListener(ResultEvent.RESULT,DeleteAMyMarkerResultHandler);
			DeleteAMyMarkerRO.addEventListener(FaultEvent.FAULT, DeleteAMyMarkerFaultHandler);
		}
		
		public function doDeleteAMyMarker(markerid:String):void
		{
			DeleteAMyMarkerRO.doDeleteAMyMarker(markerid,theModel.user.user_id);
		}
		
		internal function DeleteAMyMarkerResultHandler(event:ResultEvent):void
		{
				Alert.show("Delete Marker Successfully.");
				if(mark.searchtype.text == "myown")
					theModel.allTheTypeMarkers = event.result as ArrayCollection;
				theModel.dispatchEvent(new Event(ModelLocator.DELETEAMYMARKER_OK));
		}
		
		internal function DeleteAMyMarkerFaultHandler(event:FaultEvent):void
		{
			Alert.show("error occur when delete your marker");
		}
	}
}